<%@ page language="java" pageEncoding="UTF-8" import="ll.sms.pojo.*"%>
<%@page import="java.util.*,ll.sms.pojo.ChannelCombox,ll.sms.util.*"%>
<%@page import="ll.sms.util.AdminProperty"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>用户注册</title>
		<link rel="stylesheet" type="text/css" href="../ext/ext-all.css" />
		<script type="text/javascript" src="../ext/ext-base.js"></script>
		<script type="text/javascript" src="../ext/ext-all.js"></script>

<style type="text/css">
.settings {
	background: url(../images/cmp.gif) left top no-repeat !important;
	}

.popup {
    position: absolute;
    z-index: 50;
    border-collapse: collapse;
}

.popup td.corner {height: 15px;    width: 19px;}
.popup td#topleft { background-image: url(../images/bubble-1.png); }
.popup td.top { background-image: url(../images/bubble-2.png); }
.popup td#topright { background-image: url(../images/bubble-3.png); }
.popup td.left { background-image: url(../images/bubble-4.png); }
.popup td.right { background-image: url(../images/bubble-5.png); }
.popup td#bottomleft { background-image: url(../images/bubble-6.png); }
.popup td.bottom { background-image: url(../images/bubble-7.png); text-align: center;}
.popup td.bottom img { display: block; margin: 0 auto; }
.popup td#bottomright { background-image: url(../images/bubble-8.png); }

.popup table.popup-contents {
    font-size: 12px;
    line-height: 1.2em;
    background-color: #fff;
    color: #666;
    font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", sans-serif;
    }

table.popup-contents th {
    text-align: right;
    text-transform: lowercase;
    }

table.popup-contents td {
    text-align: left;
    }
</style>
<%
String currentUserId = SmsUtil.sessionHelper(session,AdminProperty.aid);
String defaultChannelId = SmsUtil.sessionHelper(session,AdminProperty.adefaultchannel);
List<ChannelCombox> list = SmsUtil.getChannelList(defaultChannelId);
List<ChannelCombox> list1 = SmsUtil.getChannelList(defaultChannelId);
//String defaultChannelName = SmsAppContainer.getChannelPool().get(defaultChannelId).getHname()+"(默认)";
 %>
<script type="text/javascript">
function showPopup(element_id,username){

 username = "<img alt=\"\" src=\"../img/alert.gif\"/><font color=red>"+username+"</font>";
  var div = createElement("div");
  div.id = "popup";
var x = 0;
var y = 0;

  div.innerHTML='\
        <table style="top:' + y + 'px; left:' + x + 'px;" class="popup">\
          <tbody>\
            <tr>\
              <td class="corner" id="topleft"></td>\
              <td class="top"></td>\
              <td class="corner" id="topright"></td>\
            </tr>\
            <tr>\
              <td class="left"></td>\
              <td><table class="popup-contents">\
                <tbody>\
                    <tr>\
                      <td>'+username+'</td>\
                    </tr>\
                </tbody>\
              </table></td>\
              <td class="right"></td>\
            </tr>\
            <tr>\
              <td id="bottomleft" class="corner"></td>\
              <td class="bottom"><!--<img src="../images/bubble-tail2.png" alt="popup tail" height="29" width="30">--></td>\
              <td class="corner" id="bottomright"></td>\
            </tr>\
          </tbody>\
        </table>';
  document.body.appendChild(div);
  //Element.show("popup");
}

function hidePopup(){
document.getElementById('popup').parentNode.removeChild(document.getElementById('popup'));
}

function createElement(element) {
    if (typeof document.createElementNS != 'undefined') {
        return document.createElementNS('http://www.w3.org/1999/xhtml', element);
    }
    if (typeof document.createElement != 'undefined') {
        return document.createElement(element);
    }
    return false;
}
</script>
	<script type="text/javascript">
	Ext.BLANK_IMAGE_URL = '../images/s.gif';
	window.onload = (function(){
	//Ext.QuickTips.init();
				var smsname = new Ext.form.TextField({ //text
                 id: 'uuname',
                 fieldLabel: '用户名',
                 name: 'uuname',
 				 defaultType: 'textfield',
                 grow: false,
                 regex : /^[a-zA-Z0-9_\u4e00-\u9fa5]{2,32}$/,
                 allowBlank:false,
                 blankText :'用户名必须填写',
                 regexText : "用户名允许的字符为:英文字母、中文、下划线,长度为4-32位"
             });


             smsname.on('blur', function(e){

				  if(name==''){
				  	return
				  }
                  var name = this.getValue();
				  Ext.Ajax.request({
                  url : '../ajaxjsp/system.jsp',
                  method : 'POST',
                  params : {
                  		name : name,
                  		flag : 'usernamecheck',
                  		type : 'u'
                  },
                  success: function(response, options) {
                        //获取响应的json字符串
                       var responseArray = Ext.util.JSON.decode(response.responseText);
                            if(responseArray.success==true){
								try{hidePopup();}catch(e){}
                            }
                            else{
								showPopup('uuname','['+Ext.getCmp('uuname').getValue()+"]该用户名已经被使用!");
                            }
                         }
              });
             });

		var op = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({url: '../ajaxjsp/proxycombox.jsp?adminbelong=<%=currentUserId%>'}),
        reader: new Ext.data.JsonReader({
        totalProperty: 'totalCount',
        root: 'result',
        fields :[{name:'aid'},{name:'auname'}]
        }),
        remoteSort: true
        });

		   var ops = new Ext.form.ComboBox({
		         store: op,
		         width:250,
		         readOnly:true,
		         mode: 'remote',
		         triggerAction: 'all',
		         valueField: 'aid',
		         displayField: 'auname',
		         minListWidth : 100,
		         fieldLabel: '负责业务员',
                 name: 'auname_',
                 hiddenName : 'auname',
                 id:'selectoperator',
		         pageSize : 5
		     });


	var store1 = new Ext.data.SimpleStore({
	fields: ['clazz', 'showname'],
	data : <%=ExtJsonBuilder.channel2ArrayStringNoAll(list)%>
	});

	var store2 = new Ext.data.SimpleStore({
	fields: ['clazz', 'showname'],
	data : <%=ExtJsonBuilder.channel2ArrayStringNoAll(list1)%>
	});

    var comb = new Ext.form.ComboBox({
            emptyText : '请选择',
            store: store1,
            mode:'local',
            triggerAction:'all',
            valueField: 'clazz',
            name:'adefaultchannel_',
            readOnly : true,
            id:'adefaultchannel_',
            hiddenName : 'adefaultchannel',
            displayField:'showname',
 			fieldLabel: '设置你的默认通道',
 			withd :140
            });

    var comb1 = new Ext.form.ComboBox({

            store: store2,
            mode:'local',
            readOnly : true,
            triggerAction:'all',
            valueField: 'clazz',
            name:'uchannel_',
            id:'uchannel_',
            hiddenName : 'uchannel',
            displayField:'showname',
 			fieldLabel: '使用通道',
 			withd :140
            });


  	   var win;
	   var proxystore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({url: '../ajaxjsp/proxycombox.jsp'}),
        reader: new Ext.data.JsonReader({
        totalProperty: 'totalCount',
        root: 'result',
        fields :[{name:'aid'},{name:'acompany'}]
        }),
        remoteSort: true
        });

        //proxystore.load({params:{start:0,limit:6}});

		    var belongProxy = new Ext.form.ComboBox({
		         store: proxystore,
		         width:50,
		         readOnly:true,
		         emptyText: '10',
		         mode: 'remote',
		         triggerAction: 'all',
		         valueField: 'aid',
		         displayField: 'acompany',
		         minListWidth : 220,
		         fieldLabel: '所属代理ID',
                 name: 'ucompany',
		         pageSize : 5
		     });



	    var simple = new Ext.FormPanel({
	    renderTo:'myf',
        labelWidth: 100, // label settings here cascade unless overridden
        url:'../ajaxjsp/userregdit.jsp',
        frame:true,
        title: '用户注册',
        bodyStyle:'padding:5px 5px 0',
        width: 500,
        defaults: {width: 230},
        defaultType: 'textfield',

        items: [smsname,{
                fieldLabel: '密码',
                name: 'upwd',
                vtype:'alphanum',
                vtypeText:'密码只能包括字母或者数字',
                allowBlank:false,
                blankText :'密码必须填写'
            },{
                fieldLabel: '重复密码',
                name: 'reupwd',
                vtype:'alphanum',
                vtypeText:'密码只能包括字母或者数字',
                allowBlank:false,
                blankText :'密码必须填写'
            },{
                fieldLabel: '联系人',
                name: 'ulinkman'

            },
            {
                fieldLabel: '联系方式',
                name: 'uphone'

            },
            {
                fieldLabel: '所属代理ID',
                name: 'ucompany',
                allowBlank:false,
                xtype:'hidden',
                blankText :'代理ID必须填写',
                id : 'ucompany'

            }
            ,
            {
                fieldLabel: '可发短信数',
                name: 'usmsnum',
                allowBlank:false,
                blankText :'是否启用必须填写'
            },
            {
                fieldLabel: '用户等级',
                name: 'uavailable',
                allowBlank:false,
                xtype:'hidden',
                blankText :'等级必须填写'
            },comb1,
            ops,
            {
            xtype: 'textarea',
            fieldLabel: '备注',
            name: 'unote'
            }
        ],

        buttons: [{
            text: '开户',
            handler : function(){
			simple.form.findField('ucompany').setValue('<%=currentUserId%>');
			var aunameop = simple.form.findField('auname').getValue();
			if(Ext.isEmpty(aunameop)){
			alert('你未选择业务操作员，若没有则必须先注册业务员！');
			return;
			}
			dosubmit();
           /* simple.form.submit({
					waitMsg : '正在处理......',
					success : function(form, action) {
						alert(1);
            	        form.reset();
						alert(action.result.msg);
					},
					failure : function(form, action) {
							alert(1);
							if (action.failureType == Ext.form.Action.SERVER_INVALID){
							alert(action.result.errors.msg);
							}
							alert(action.result.msg);

					}
				});*/
            }
        },{
            text: '重填',
            handler : function(){
          		simple.form.reset();
            }
        }]
    });

   function createWin(){
    if(win){
    return win;
    }
    var form  = new Ext.form.FormPanel({
	lableAlign:'right',
	url:'../ajaxjsp/adminchannelinit.jsp',
	lablewidth:'80',
	frame:true,
	defaultType:'textfield',
	items:[comb]
	});

    win = new Ext.Window({
    			title 		: '你未设置默认通道',
                applyTo     : 'regeditchannel',
                layout      : 'fit',
                width       : 320,
                height      : 150,
                closeAction :'hide',
                plain       : true,
                items       : [form],

                buttons: [{
                    text     : '提交',
                    handler  : function(){
                    form.form.submit({
					waitMsg : '正在处理......',
					success : function(form, action) {
						 doHide();
						},
					failure : function(form, action) {
						if (action.failureType == Ext.form.Action.SERVER_INVALID){
							alert(action.result.errors.msg);
							}else{
							alert('操作失败');
							}
						}
					});
                    }

                },{
                    text     : '关闭',
                    handler  : function(){
                        win.hide();
                    }
                }]
            });

	return win;
   }
 function doHide(){
            win.hide();
            }

            function dosubmit(){

			 simple.form.submit({

					waitMsg : '正在处理......',
					success : function(form, action) {
            	        simple.form.reset();
						alert(action.result.msg);
					},
					failure : function(form, action) {
						if (action.failureType == Ext.form.Action.SERVER_INVALID){
							alert(action.result.errors.msg);
							return;
							}else{
							alert('--------非法输入-------');
							}
					}
				});
			}
    });
	</script>

  </head>

  <body bgcolor="#ffffff">
 <br>
     <div id="myf" align="center"></div>
     <div id="regeditchannel" class="x-hidden"></div>
  </body>
</html>
